
import 'package:flutter/material.dart';
import 'package:flutter_elf/config/component_index.dart';
import 'package:fluttertoast/fluttertoast.dart';

abstract class BaseCommon{

  BuildContext _contextBaseFunction;

  Widget getBaseView(BuildContext context){
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: initAppbar(),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: ()=>FocusScope.of(context).requestFocus(FocusNode()),
        child: buildView(context),
      ),
      bottomNavigationBar: getBottomBar(context),
    );
  }

  Widget getBottomBar(context);

  Widget buildView(BuildContext context);

  void initBaseCommon(State state, BuildContext context) {
    _contextBaseFunction = context;
  }
  PreferredSizeWidget initAppbar();

  void onCreate();

  void onResume();

  void onPause();

  void onDestroy();

  String getClassName() {
    return this.runtimeType.toString();
  }

  showToast(String msg){
    if (msg != null) {
      if (msg != null && msg.isNotEmpty) {
        Fluttertoast.showToast(msg: msg, fontSize: 13.0);
      }
    }
  }

  logs(String log){
    _log(getClassName() + '      '+ log);
  }

  static _log(String bodyMsg){
    if (bodyMsg.length > 1000) {
      for (int i = 0; i < bodyMsg.length; i += 1000) {
        if (i + 1000 < bodyMsg.length) {
          globalPrint(bodyMsg.substring(i, i + 1000));
        } else {
          globalPrint(bodyMsg.substring(i, bodyMsg.length));
        }
      }
    } else {
      globalPrint(bodyMsg);
    }
  }
}